package com.sky.com.sky.mapper;

import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {

    void insert(Orders orders);

    /**
     * 根据订单号查询订单
     * **/
    @Select("select * from orders where number = #{orderBumber}")
    Orders getByNumber(String orderNumber);

    // 修改订单信息
    void update(Orders orders);

    // 条件查询订单列表
    List<OrderVO> getList(OrdersPageQueryDTO ordersPageQueryDTO);

    //查询总数
    @Select("select count(*) from orders where status=#{status}")
    Integer gettotal(Integer status);

    // 根据id查询订单
    @Select("select * from orders where id =#{id}")
    Orders getById(Long id);

    //修改订单状态
    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> getByStatusAndOrdertimeLT(Integer status,LocalDateTime orderTime);

    // 查询指定状态和时间的营业额
    Double sumTurnover(Integer status, LocalDate currentDate);

    // 统计订单数量
    Integer countOrder(Integer status, LocalDate currentDate);

    // 查询时间区间内的销量排名
    List<GoodsSalesDTO> getSalesTop10(LocalDate begin, LocalDate end);

    Integer orderCountByDate1(Integer status, LocalDate begin, LocalDate end);


    @Select("select sum(amount) from orders wherre status =5 and date(order_time) between #{begin} and {end}")
    BigDecimal getSumTurnover1(LocalDate begin,LocalDate end);

    List<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据状态统计订单数量
     * @param status
     * **/
   @Select("select count(*) from orders where status = #{status}")
   Integer countStatus(Integer status);

    @Select("select * from orders where status = #{status} and order_time < date_sub(now(),interval #{minute} minute)")
    List<Orders> getByStatusAndOrderTime(Integer status, int monute);
}
